﻿namespace MyPlugIn
{
    #region 命名空间

    using System;
    using System.Collections.Concurrent;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Kuge.DataExchange.PlugIn;
    using System.Windows.Forms;

    using System.IO;
    using System.Xml;

    #endregion

    public class CustomPlugIn : Kuge.DataExchange.PlugIn.IPlugIn
    {
        #region 全局

        private System.Drawing.Icon ICON = null;

        private MyPlugIn.frmTest TestWindow;

        private Dictionary<string, string> InfoDict = new Dictionary<string, string>();

        private Dictionary<string, string> Columns = new Dictionary<string, string>();

        #endregion

        #region 属性

        public string UserName { set; get; }

        #endregion

        #region 事件(通知exe)

        /// <summary>
        /// 有事发生
        /// 第一个参数:事件名称 
        /// 第二个参数:是否错误
        /// 第三个参数:事件参数
        /// </summary>
        public event Action<string, bool, object> Happended;

        internal void SendBarcode(int channel,string barcode)
        {
            string[] args = new string[2];
            args[0] = channel.ToString();
            args[1] = barcode;
            Happended?.BeginInvoke("BARCODE", false, args, null, null);
        }

        internal void SendParameter(string name, string content)
        {
            string[] args = new string[2];
            args[0] = name;
            args[1] = content;
            Happended?.BeginInvoke("PARAMETER", false, args, null, null);
        }

        internal void ShowDialog(string msg)
        {
            Happended?.BeginInvoke("DIALOG", false, msg, null, null);
        }

        internal void ShowTips(bool isError, string msg)
        {
            Happended?.BeginInvoke("MESSAGE", isError, msg, null, null);
        }

        internal void ShowBlockTips(bool isError, string title, string msg)
        {
            Happended?.BeginInvoke("TEXT", isError, new string[] { title, msg }, null, null);
        }

        #endregion

        #region 构造函数

        public CustomPlugIn()
        {
            #region 数据库列字典

            //Key:数据简码
            //Value:数据库字段名称,按实际进行修改

            //Columns.Add("N02", "设备编号");
            //Columns.Add("N01", "数据长度");
            //Columns.Add("N40", "固定资产编号");
            //Columns.Add("N41", "自定义信息1");
            //Columns.Add("N42", "自定义信息2");
            //Columns.Add("N0C", "设备固件");
            //Columns.Add("N11", "固件校验值");
            //Columns.Add("N10", "参数校验值");
            //Columns.Add("N08", "通道号");
            //Columns.Add("N0D", "产品型号");
            //Columns.Add("N05", "环境温度");
            //Columns.Add("N00", "是否通过");
            //Columns.Add("N0A", "错误代码");
            //Columns.Add("N0F", "花费时间");
            //Columns.Add("N13", "电芯条码");
            //Columns.Add("N03", "电池条码");
            //Columns.Add("N14", "探针剩余");
            //Columns.Add("N24", "转接板剩余");
            //Columns.Add("F00", "条码判定");
            //Columns.Add("N16", "数据文件");
            //Columns.Add("N1F", "生产阶段");
            //Columns.Add("N25", "测试阶段");
            //Columns.Add("N20", "总线电压");
            //Columns.Add("N21", "总线速率");
            //Columns.Add("N26", "项目ID");
            //Columns.Add("N04", "日期");
            Columns.Add("D00", "开路电压1");
            Columns.Add("D30", "CELL电压");
            Columns.Add("D31", "CELL-PACK");
            Columns.Add("D2B", "K值");
            Columns.Add("D02", "交流阻抗(mΩ)");
            Columns.Add("D03", "R1");
            Columns.Add("D04", "R1");
            Columns.Add("D05", "R2");
            Columns.Add("D06", "电容");
            Columns.Add("D21", "电容");
            Columns.Add("D2E", "R2");
            Columns.Add("D09", "放电电压");
            Columns.Add("D32", "放电PACK电压");
            Columns.Add("D33", "放电CELL电压");
            Columns.Add("D34", "放电CELL-PACK");
            Columns.Add("D0A", "放电电流");
            Columns.Add("D0B", "直流阻抗(mΩ)");
            Columns.Add("D1E", "一级放电过流延时");
            Columns.Add("D0E", "放电过流延时");
            Columns.Add("D0F", "放电过流电流");
            Columns.Add("D0C", "充电电压");
            Columns.Add("D35", "充电PACK电压");
            Columns.Add("D36", "充电CELL电压");
            Columns.Add("D37", "充电PACK-CELL");
            Columns.Add("D0D", "充电电流");
            Columns.Add("D38", "一级过压下限");
            Columns.Add("D39", "一级过压下限电流");
            Columns.Add("D3A", "一级过压上限");
            Columns.Add("D3B", "一级过压上限电流");
            Columns.Add("D3C", "二级过压下限");
            Columns.Add("D3D", "二级过压下限电流");
            Columns.Add("D3E", "二级过压上限");
            Columns.Add("D3F", "二级过压上限电流");
            Columns.Add("D40", "欠压上限");
            Columns.Add("D41", "欠压上限电流");
            Columns.Add("D42", "欠压下限");
            Columns.Add("D43", "欠压下限电流");
            Columns.Add("D1F", "充电漏电流");
            Columns.Add("D20", "放电漏电流");
            Columns.Add("D10", "充电过流延时");
            Columns.Add("D11", "充电过流电流");
            Columns.Add("D12", "短路保护延时");
            Columns.Add("D13", "短路后电压");
            Columns.Add("D14", "短路恢复后电压");
            Columns.Add("D2F", "短路前后压差");
            Columns.Add("D22", "HDQ电压(V)");
            Columns.Add("D23", "SDA电压(V)");
            Columns.Add("D24", "SCL电压(V)");
            Columns.Add("D25", "V1 电压(V)");
            Columns.Add("D26", "CELL电压");
            Columns.Add("D2C", "PACK电压(V)");
            Columns.Add("D2D", "CELL偏差(V)");
            Columns.Add("D27", "辅助电阻(KΩ)");
            Columns.Add("D28", "绝缘阻抗(MΩ)");
            Columns.Add("D29", "绝缘漏电(V)");
            Columns.Add("D01", "开路电压2");
            Columns.Add("D2A", "开路压差(mV)");
            Columns.Add("D44", "CR+");
            Columns.Add("D45", "CR-");
            Columns.Add("D4D", "R3(KΩ)");
            Columns.Add("D70", "历史电压");
            Columns.Add("D50", "电压差");
            Columns.Add("D51", "CR+(R1)(KΩ)");
            Columns.Add("D52", "CR-(R1)(KΩ)");
            Columns.Add("D53", "完成开路电压(V)");
            Columns.Add("D54", "完成交流阻抗(mΩ)");
            Columns.Add("D55", "完成交流阻抗偏差(mΩ)");
            Columns.Add("D56", "完成充电压升(V)");
            Columns.Add("D57", "完成充电电流(A)");
            Columns.Add("D58", "完成放电压降(V)");
            Columns.Add("D59", "完成放电电流(A)");
            Columns.Add("D61", "放电过流后电压");
            Columns.Add("D71", "DET");
            Columns.Add("D72", "电压档位");
            Columns.Add("D73", "电压档位代号");
            Columns.Add("D74", "保护后R2(KΩ)");
            Columns.Add("D75", "DET2");
            Columns.Add("D76", "R1温差(℃)");
            Columns.Add("D77", "R2温差(℃)");
            Columns.Add("D78", "容量电压档位");
            Columns.Add("D7B", "内阻档位");
            Columns.Add("D7C", "内阻档位代号");
            Columns.Add("D7D", "SC UnProtected(ms)");
            //Columns.Add("P00", "Page1");
            //Columns.Add("P01", "Page2");
            //Columns.Add("P02", "Page3");
            //Columns.Add("P03", "Page4");
            //Columns.Add("P04", "Page5");
            //Columns.Add("P05", "Page6");
            //Columns.Add("P06", "Page7");
            //Columns.Add("P07", "Page8");
            //Columns.Add("P08", "Page9");
            //Columns.Add("P09", "Page10");
            //Columns.Add("P0A", "Page11");
            //Columns.Add("P0B", "Page12");
            //Columns.Add("P0C", "Page13");
            //Columns.Add("P0D", "Page14");
            //Columns.Add("P0E", "Page15");
            //Columns.Add("P0F", "Page16");
            //Columns.Add("P10", "Page17");
            //Columns.Add("P11", "Page18");
            //Columns.Add("P12", "Page19");
            //Columns.Add("P13", "Page20");
            //Columns.Add("P14", "Page21");
            //Columns.Add("P15", "Page22");
            //Columns.Add("P16", "Page23");
            //Columns.Add("P17", "Page24");
            //Columns.Add("P18", "Page25");
            //Columns.Add("P19", "Page26");
            //Columns.Add("P1A", "Page27");
            //Columns.Add("P1B", "Page28");
            //Columns.Add("P1C", "Page29");
            //Columns.Add("P1D", "Page30");
            //Columns.Add("P1E", "Page31");
            //Columns.Add("P1F", "Page32");
            //Columns.Add("PFF", "EPR ERR");
            //Columns.Add("PF0", "Family Code");
            //Columns.Add("PF1", "ROM Code");
            //Columns.Add("D6F", "Initial Status");
            //Columns.Add("D46", "Unique ID");
            //Columns.Add("D47", "Device ID");
            //Columns.Add("D48", "Customr ID");
            //Columns.Add("D49", "Barcode Verify");
            //Columns.Add("D4A", "Authentication");
            //Columns.Add("D4B", "Authentication Data");
            //Columns.Add("D4C", "Memory Data");
            //Columns.Add("D62", "Original Data");
            //Columns.Add("D63", "Error Code");
            //Columns.Add("D64", "PCM Verson");
            //Columns.Add("D65", "Decrement Counter");
            //Columns.Add("D66", "Life Span Counter 3");
            //Columns.Add("D67", "Organization");
            //Columns.Add("D68", "Common Name");
            //Columns.Add("D69", "Public Key X");
            //Columns.Add("D6A", "Public Key Y");
            //Columns.Add("D6B", "Certificate Memory ");
            //Columns.Add("D6C", "EE Lock Status");
            //Columns.Add("D6D", "Status");
            //Columns.Add("D6E", "Auth-Page0");
            //Columns.Add("D79", "Barcode Verify II");
            //Columns.Add("D7A", "Memory Data II");
            //Columns.Add("E80", "Initial Lock Status");
            //Columns.Add("E81", "Log00");
            //Columns.Add("E82", "Log01");
            //Columns.Add("E83", "Log02");
            //Columns.Add("E84", "Log03");
            //Columns.Add("E85", "Log04");
            //Columns.Add("E86", "Log05");
            //Columns.Add("E87", "Log06");
            //Columns.Add("E88", "Log07");
            //Columns.Add("E89", "Log08");
            //Columns.Add("E8A", "Log09");
            //Columns.Add("E8B", "Log10");
            //Columns.Add("E8C", "Log11");
            //Columns.Add("E8D", "Log12");
            //Columns.Add("E8E", "Log13");
            //Columns.Add("E8F", "Log14");
            //Columns.Add("EFF", "Final Lock Status");
            //Columns.Add("G00", "★CHIP ID");
            //Columns.Add("G01", "★HW Version");
            //Columns.Add("G02", "★FW Version");
            //Columns.Add("G29", "★Chemistry ID");
            //Columns.Add("G26", "★Chemistry Checksum");
            //Columns.Add("G27", "★Static DF Checksum");
            //Columns.Add("G28", "★All DF Checksum");
            //Columns.Add("G05", "★GG温度");
            //Columns.Add("G06", "★GG温度精度");
            //Columns.Add("G07", "★GG内部温度");
            //Columns.Add("G08", "★GG温度精度");
            //Columns.Add("G09", "★开路实际电压");
            //Columns.Add("G0A", "★开路GG电压");
            //Columns.Add("G0B", "★开路GG电压精度");
            //Columns.Add("G1C", "★开路电芯1电压");
            //Columns.Add("G1D", "★开路电芯2电压");
            //Columns.Add("G60", "★开路电芯3电压");
            //Columns.Add("G61", "★开路电芯4电压");
            //Columns.Add("G1E", "★开路电芯压差(mV)");
            //Columns.Add("G3F", "★开路电流(mA)");
            //Columns.Add("G0C", "★放电实际电流");
            //Columns.Add("G0D", "★放电GG电流");
            //Columns.Add("G0E", "★放电GG电流精度");
            //Columns.Add("G22", "★放电电芯1电压");
            //Columns.Add("G23", "★放电电芯2电压");
            //Columns.Add("G64", "★放电电芯3电压");
            //Columns.Add("G65", "★放电电芯4电压");
            //Columns.Add("G24", "★放电电芯压差(mV)");
            //Columns.Add("G0F", "★充电实际电流");
            //Columns.Add("G10", "★充电GG电流");
            //Columns.Add("G11", "★充电GG电流精度");
            //Columns.Add("G1F", "★充电电芯1电压");
            //Columns.Add("G20", "★充电电芯2电压");
            //Columns.Add("G62", "★充电电芯3电压");
            //Columns.Add("G63", "★充电电芯4电压");
            //Columns.Add("G21", "★充电电芯压差(mV)");
            //Columns.Add("G12", "★Design CAP.");
            //Columns.Add("G43", "★Qmax Cell 0");
            //Columns.Add("G47", "★Update Status");
            //Columns.Add("G46", "★Over Temp");
            //Columns.Add("G2B", "★Nominal CAP.");
            //Columns.Add("G2C", "★Full Available CAP.");
            //Columns.Add("G14", "★Remainning CAP.");
            //Columns.Add("G13", "★Full CHG CAP.");
            //Columns.Add("G15", "★SOC");
            //Columns.Add("G67", "★Unfiltered SOC");
            //Columns.Add("G6A", "★SOC Diff");
            //Columns.Add("G59", "★SOC2");
            //Columns.Add("G68", "★Unfiltered SOC2");
            //Columns.Add("G6B", "★SOC Diff2");
            //Columns.Add("G6C", "★SOC Delta");
            //Columns.Add("G6D", "★Write T Rise");
            //Columns.Add("G6E", "★Read T Rise I");
            //Columns.Add("G6F", "★Read T Rise II");
            //Columns.Add("G69", "★GPIO Test");
            //Columns.Add("G70", "★HMAC Authentication");
            //Columns.Add("G71", "★Device Name");
            //Columns.Add("G16", "★SOH");
            //Columns.Add("G18", "★Cycle Count");
            //Columns.Add("G17", "★Standby Current");
            //Columns.Add("G2D", "★MaxLoad Current");
            //Columns.Add("G31", "★Lifetime MaxTemp");
            //Columns.Add("G32", "★Lifetime MinTemp");
            //Columns.Add("G33", "★Lifetime MaxPackVoltage");
            //Columns.Add("G34", "★Lifetime MinPackVoltage");
            //Columns.Add("G35", "★Lifetime MaxChgCurrent");
            //Columns.Add("G36", "★Lifetime MaxDsgCurrent");
            //Columns.Add("G30", "★Pack Config");
            //Columns.Add("G72", "★Pack Config B");
            //Columns.Add("G73", "★Lifetime");
            //Columns.Add("G74", "★Manufacture Date");
            //Columns.Add("G2E", "★BTPSOC1 Set");
            //Columns.Add("G2F", "★BTPSOC1 Clear");
            //Columns.Add("G40", "★Parameter Revision");
            //Columns.Add("G44", "★Sleep Current");
            //Columns.Add("G45", "★Terminate Voltage");
            //Columns.Add("G4B", "★Charging Voltage");
            //Columns.Add("G4C", "★Taper Current");
            //Columns.Add("G4D", "★Min Taper Capacity");
            //Columns.Add("G4E", "★Taper Voltage");
            //Columns.Add("G4F", "★Current Taper Window");
            //Columns.Add("G50", "★TCA Set");
            //Columns.Add("G51", "★TCA Clear");
            //Columns.Add("G52", "★FC Set");
            //Columns.Add("G53", "★FC Clear");
            //Columns.Add("G55", "★Sleep CHG");
            //Columns.Add("G66", "★Full Sleep");
            //Columns.Add("G56", "★Manufacture Name");
            //Columns.Add("G57", "★Manufacture Date");
            //Columns.Add("G58", "★Serial Number");
            //Columns.Add("G19", "★Control Status 1");
            //Columns.Add("G49", "★Flags 1");
            //Columns.Add("G1A", "★Control Status 2");
            //Columns.Add("G4A", "★Flags 2");
            //Columns.Add("G03", "★SEAL");
            //Columns.Add("G04", "★UnSeal");
            //Columns.Add("G1B", "★使能Gauging");
            //Columns.Add("G2A", "★SLEEP");
            //Columns.Add("G41", "★Reset");
            //Columns.Add("G25", "★Shutdown");
            //Columns.Add("GA0", "★INA231 Wakeup");
            //Columns.Add("GA1", "★INA231 CAL BKP");
            //Columns.Add("GA2", "★INA231 CAL");
            //Columns.Add("GA6", "★INA231 Shutdown");
            //Columns.Add("GA7", "★INA231 VOLT");
            //Columns.Add("GA8", "★INA231 VOLT ACC1");
            //Columns.Add("GA9", "★INA231 VOLT ACC2");
            //Columns.Add("GAA", "★INA231 CHGC");
            //Columns.Add("GAD", "★INA231 DSGC");
            //Columns.Add("G80", "★Dataflash比对");
            //Columns.Add("G81", "★写Manufacturer Data");
            //Columns.Add("G90", "★PCM SN");
            //Columns.Add("G91", "★PACK SN");
            //Columns.Add("G95", "★Manufacturer Info B String");
            //Columns.Add("GE0", "★Sealed");
            //Columns.Add("GE1", "★QEN");
            //Columns.Add("GE2", "★GAUGE_EN");
            //Columns.Add("GE3", "★LT_EN");
            //Columns.Add("E00", "A_D_RES");
            //Columns.Add("E01", "A_K_RES");
            //Columns.Add("E02", "C_V_RES");
            //Columns.Add("E03", "F_C_RES");
            //Columns.Add("E04", "I_S_V_RES");
            //Columns.Add("E05", "M_D_RES");
            //Columns.Add("E06", "P_S_B_RES");
            //Columns.Add("E07", "P_V_RES");
            //Columns.Add("E08", "U_ID_RES");
            //Columns.Add("E09", "X_ID_RES");

            #endregion
        }

        #endregion

        #region 方法(由exe调用)

        /// <summary>
        /// 运行后的登陆界面
        /// </summary>
        /// <returns></returns>
        public Result Login()
        {
            #region Login

            Result Ret = null;

            //Happended?.BeginInvoke
            //(
            //    "MODIFY",
            //    false,
            //    new object[]
            //    {
            //        "LISTVIEW_ITEM"/*string,固定指令                               */,
            //        "登陆时间"/*string,固定指令                               */,
            //        DateTime.Now.ToString()  /*string,文件名,显示于标题栏和状态栏            */
            //    },
            //    null,
            //    null
            //);

#if true1

            //在此处弹出设置工单等信息的界面
            frmLogin f = new frmLogin("LOGIN", UserName);
            f.Icon = ICON;
            if (f.ShowDialog() == System.Windows.Forms.DialogResult.Yes)
            {
                UserName = f.UserName;

                //可选,BTS可能会通过Pull("GET_INFO")获取
                //InfoDict.Add("PROJECT", "机种型号");
                //InfoDict.Add("PROCESS", "工序");
                //InfoDict.Add("LINE", "拉别");
                //InfoDict.Add("USER", UserName);

                Ret = new Result(true,@"D:\Parameter.xml");
            }
            else
            {
                Ret = new Result(false, "登陆", "登陆失败");
            }
#else
            //Ret = new Result(true, new FileNotFoundException("神马文件都没有"));
#endif

#if false

            //加载自定义界面
            TestWindow = new frmTest(this);
            TestWindow.Show(); 

#endif

            return Ret;

            #endregion
        }

        /// <summary>
        /// 弹出输入用户名和密码的界面
        /// </summary>
        /// <param name="WhatToDo"></param>
        /// <returns></returns>
        public Result VerifyPassword(string WhatToDo)
        {
            #region VerifyPassword

            Result Ret = null;

#if false
            frmLogin f = new frmLogin(WhatToDo, UserName);
            switch (f.ShowDialog())
            {
                case System.Windows.Forms.DialogResult.Yes:
                    {
                        UserName = f.UserName;
                        Ret = new Result(true);
                        break;
                    }
                case System.Windows.Forms.DialogResult.No:
                    {
                        UserName = f.UserName;
                        Ret = new Result(false, WhatToDo, "告诉我,你想干嘛?");
                        break;
                    }
                default:
                    {
                        Ret = new Result(false, WhatToDo, "用户取消!");
                        break;
                    }
            } 
#endif

            return Ret;

            #endregion
        }

        /// <summary>
        /// 执行指定操作,预留
        /// </summary>
        /// <param name="Operation"></param>
        /// <returns></returns>
        public Result Execute(string Operation)
        {
            #region Execute

            Result Ret = null;

            return Ret;

            #endregion
        }

        /// <summary>
        /// 拉取数据
        /// 比如,查询条码是否已完成某些工序
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public Result Pull(string Operation, params object[] Parameters)
        {
            #region Pull

            Result Ret = null;

            switch (Operation)
            {
                case "GET_INFO":
                    {
                        #region GET_INFO

                        #region 添加插件信息

                        Dictionary<string, string> Info = new Dictionary<string, string>();

                        //插件供应商名称
                        Info.Add("PLUGIN_VENDOR", "Kuge");
                        //插件版本号
                        Info.Add("PLUGIN_VERSION", "1.0.0.0");
                        //插件发布日期
                        Info.Add("PLUGIN_RELEASE_DATETIME", "2019/12/25");
                        //备注
                        Info.Add("PLUGIN_REMARK", "插件演示");

                        #endregion

                        Ret = new Result(true, Info); 

                        #endregion
                        break;
                    }
                case "GET_BARCODE_BY_CELL_BARCODE":
                    {
                        #region GET_BARCODE_BY_CELL_BARCODE

                        #endregion
                        break;
                    }
                case "CHECK_BARCODE_RULE":
                    {
                        #region CHECK_BARCODE_RULE
                        #endregion
                        break;
                    }
                case "CHECK_BARCODE":
                    {
                        #region CHECK_BARCODE

                        string Barcode, Project, Model, Comments;

                        Barcode = (string)Parameters[0];
                        Project = (string)Parameters[1];
                        Model = (string)Parameters[2];
                        Comments = (string)Parameters[3];

                        Ret = new Result(true);

                        //if (sResult == "TRUE")
                        //{
                        //    Ret = new Result(true);
                        //}
                        //else
                        //{
                        //    Ret = new Result(false, "条码检查", sResult);
                        //}

                        #endregion
                        break;
                    }
                case "PARAMETER":
                    {
                        #region PARAMETER

                        //加载参数(可改为从服务器加载)
                        OpenFileDialog dlg = new OpenFileDialog();
                        dlg.Filter = "*.xml|*.xml";
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            string XMLString;

                            XMLString = System.IO.File.ReadAllText(dlg.FileName);

                            Ret = new Result(true, Operation, "Successful", XMLString);
                        }

                        #endregion
                        break;
                    }
            }

            return Ret;

            #endregion
        }

        /// <summary>
        /// 推送数据
        /// 比如,上传测试结果
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public Result Push(string Operation, params object[] Parameters)
        {
            #region Push

            Result Ret = null;

            switch (Operation)
            {
                case "K_VALUE_PARA":
                    {
                       
                        break;
                    }
                case "SET_LANGUAGE":
                    {
                        string Language = (string)Parameters[0];
                        break;
                    }
                case "SET_ICON":
                    {
                        ICON = (System.Drawing.Icon)Parameters[0];
                        break;
                    }
                case "PARAMETER":
                    {
                        #region PARAMETER

                        string XMLString, Project, Model, Comments;

                        XMLString = (string)Parameters[0];
                        Project = (string)Parameters[1];
                        Model = (string)Parameters[2];
                        Comments = (string)Parameters[3];

                        //保存参数(可改为保存到服务器)
                        //SaveFileDialog dlg = new SaveFileDialog();
                        //dlg.Filter = "*.xml|*.xml";
                        //if (dlg.ShowDialog() == DialogResult.OK)
                        //{
                        //    System.IO.File.WriteAllText(dlg.FileName, XMLString, Encoding.UTF8);

                        //    Ret = new Result(true,"保存参数","操作成功");
                        //}

                        #endregion
                        break;
                    }
                case "UPLOAD_DATA":
                    {
                        #region UPLOAD_DATA

                        bool AllPassed;
                        List<Kuge.DataExchange.PlugIn.DataItem> PlugInData = new List<Kuge.DataExchange.PlugIn.DataItem>();
                        string Barcode, CellBarcode;

                        AllPassed = (bool)Parameters[0];
                        PlugInData = (List<Kuge.DataExchange.PlugIn.DataItem>)Parameters[1];
                        Barcode = (string)Parameters[2];
                        CellBarcode = (string)Parameters[3];

                        //可以此处进行K值计算并弹出显示

                        #region 存储到SQL SERVER/MySQL/....数据库中

                        string SQL_CommandString;
                        StringBuilder DataColumns = new StringBuilder();
                        StringBuilder DataValues = new StringBuilder();
                        foreach (var v in PlugInData)
                        {
                            //请事先定制各简码对应的列名
                            //通过private Dictionary<string, string> Columns = new Dictionary<string, string>();将简码转成所需要的数据库列名

                            //将简码和数据库字段进行对应
                            if (Columns.ContainsKey(v.Key))
                            {
                                //列名
                                DataColumns.AppendFormat("[{0}],", Columns[v.Key]);
                                //列的值
                                DataValues.AppendFormat("'{0}',", v.Value);
                            }
                        }
                        //去掉最后一个逗号
                        DataColumns.Remove(DataColumns.Length - 1, 1);
                        DataValues.Remove(DataValues.Length - 1, 1);

                        SQL_CommandString = "INSERT INTO [MyTable] (" + DataColumns.ToString() + ") VALUES (" + DataValues.ToString() + ")";

                        //INSERT INTO [MyTable] 
                        //([开路电压1],[CELL电压],[CELL-PACK],[K值],[交流阻抗(mΩ)],[R1],[R1],[R2],[电容],[电容],[R2],[放电电压],[放电PACK电压],[放电CELL电压],[放电CELL-PACK],[放电电流],[直流阻抗(mΩ)],[一级放电过流延时],[放电过流延时],[放电过流电流],[充电电压],[充电PACK电压],[充电CELL电压],[充电PACK-CELL],[充电电流],[一级过压下限],[一级过压下限电流],[一级过压上限],[一级过压上限电流],[二级过压下限],[二级过压下限电流],[二级过压上限],[二级过压上限电流],[欠压上限],[欠压上限电流],[欠压下限],[欠压下限电流],[充电漏电流],[放电漏电流],[充电过流延时],[充电过流电流],[短路保护延时],[短路后电压],[短路恢复后电压],[短路前后压差],[HDQ电压(V)],[SDA电压(V)],[SCL电压(V)],[V1 电压(V)],[CELL电压],[PACK电压(V)],[CELL偏差(V)],[辅助电阻(KΩ)],[绝缘阻抗(MΩ)],[绝缘漏电(V)],[开路电压2],[开路压差(mV)],[CR+],[CR-],[R3(KΩ)],[历史电压],[电压差],[CR+(R1)(KΩ)],[CR-(R1)(KΩ)],[完成开路电压(V)],[完成交流阻抗(mΩ)],[完成交流阻抗偏差(mΩ)],[完成充电压升(V)],[完成充电电流(A)],[完成放电压降(V)],[完成放电电流(A)],[放电过流后电压],[DET],[电压档位],[电压档位代号],[保护后R2(KΩ)],[DET2],[R1温差(℃)],[R2温差(℃)],[容量电压档位],[内阻档位],[内阻档位代号],[SC UnProtected(ms)])
                        //VALUES 
                        //('3.01529','5.10742','8.97018','9.75932','9.51542','5.53794','7.55033','8.30841','4.67948','5.44797','9.26362','2.99481','4.21570','3.12872','1.32078','5.78079','0.56555','0.61456','1.73310','5.84031','1.87285','2.79784','9.57232','8.51846','8.33920','1.82444','9.42004','4.32758','9.76299','9.68172','3.46814','5.54390','5.75131','7.64046','4.41405','1.35883','3.60563','2.06437','0.02985','7.77281','1.79086','2.57681','7.29495','0.73733','9.52301','9.67838','6.59106','8.15413','1.57267','3.99022','4.59337','4.59269','6.50422','4.89518','0.85692','0.21745','5.53510','0.45172','1.42012','7.69098','6.11790','3.22274','8.54542','4.99776','1.97982','3.71973','7.24350','6.57524','8.71467','9.96195','2.17516','8.50118','0.58471','3.96029','4.04945','9.29604','5.50290','8.83500','8.99545','8.66082','5.23338','1.26590','2.75492')

                        Console.WriteLine(SQL_CommandString);

                        #endregion

                        //StringBuilder sb = new StringBuilder();
                        //foreach(var v in PlugInData)
                        //{
                        //    sb.AppendFormat("{0}:{1},{2},{3}\r\n", v.Key, Columns[v.Key],v.Description, v.Value);
                        //}
                        //ShowBlockTips(false, "我就想看看是什么东西", sb.ToString());

                        //参数:
                        //参数1:是否成功:总结论,包括测试和系统卡站之类的总结论
                        //参数2:主题:作为提示信息的主题,比如"数据上传"
                        //参数3:详细消息:作为提示信息的内容,比如"操作成功"
                        //参数4:信号:让设备输出Pass or fail信号给PLC

                        Happended?.BeginInvoke
                        (
                            "K_VALUE",
                            true,
                            new object[]
                            {
                                (int)1/*int*/,
                                (string)"0.123456"/*string*/,
                                "L"/*string,可选值:L,H,P,F*/
                            },
                            null,
                            null
                        );

                        Ret = new Result(false,"上传","成功",true);

                        //示例:
                        //成功
                        //Ret = new Result(true, "上传", "OVER", true);
                        //失败:
                        //Ret = new Result(false,"上传","失败", false);
                        //异常:
                        //Ret = new Result(false,"上传","异常",ex, false);

                        #endregion
                        break;
                    }
                case "UPLOAD_HISTORY_DATA":
                    {
                        #region UPLOAD_HISTORY_DATA

                        bool AllPassed;
                        StringBuilder ResultBuilder, ErrorBuilder;
                        string Barcode, CellBarcode;

                        AllPassed = (bool)Parameters[0];
                        ResultBuilder = (StringBuilder)Parameters[1];
                        ErrorBuilder = (StringBuilder)Parameters[2];
                        Barcode = (string)Parameters[3];
                        CellBarcode = (string)Parameters[4];

                        //参数:
                        //是否成功:总结论
                        //主题:作为提示信息的主题,比如"数据上传"
                        //消息:作为提示信息的内容,比如"操作成功"
                        //信号:让设备输出Pass or fail信号给PLC

                        //Ret = new Result(true,"上传", ResultBuilder.ToString(), true);

                        //成功
                        Ret = new Result(true, "上传", "OVER", true);
                        //失败:
                        //Ret = new Result(false,"上传","失败", false);
                        //异常:
                        //Ret = new Result(false,"上传","异常",ex, false);

                        #endregion
                        break;
                    }
            }

            return Ret;

            #endregion
        }

        #endregion
    }
}
